package com.usian.common.untils;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @projectName: day01_mohongwei
 * @package: com.jiyun.untils
 * @className: Result
 * @author: 莫洪维
 * @email: 1204315800@qq.com
 * @description: 标识类
 * @date: 2023/7/26 10:32
 */
@Data
public class Result {
    /**
     * 标识
     */
    private Boolean success;
    /**
     * 状态码
     */
    private Integer code;
    /**
     * 传递信息
     */
    private String message;
    /**
     * 传递数据
     */
    private Map<String,Object> data = new HashMap<>();

    /**
     * 通过方法
     * @return Result
     */
    public static Result ok(){
        Result r = new Result();
        r.setSuccess(true);
        r.setCode(20000);
        r.setMessage("成功");
        return r;
    }

    /**
     * 未通过方法
     * @return Result
     */
    public static Result error(){
        Result r = new Result();
        r.setSuccess(false);
        r.setCode(20001);
        r.setMessage("失败");
        return r;
    }

    public Result success(Boolean success){
        this.success = success;
        return this;
    }
    public Result code(Integer code){
        this.code = code;
        return this;
    }
    public Result message(String message){
        this.message = message;
        return this;
    }
    public Result data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

}
